package cn.fl.capital.controller;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.capital.condition.CapAdvFundQueryCondition;
import cn.fl.capital.constant.CapAdvFundConstant;
import cn.fl.capital.service.ICapAdvBackFundLogService;
import cn.fl.capital.vo.CapAdvFundVO;
import com.alibaba.fastjson.JSONObject;
import cn.fl.framework.base.context.CurrentThreadContext;
import net.sf.json.JSONArray;

/**
 * @Description:租赁项目资产资金回款记录
 */
@Controller
@RequestMapping("/capital/capAdvBackFundLog")
public class CapAdvBackFundLogController extends BaseController {
	private static final Logger logger = LoggerFactory.getLogger(CapAdvBackFundLogController.class);
	/**
	 * 资金回款记录 服务层BEAN
	 */
	@Autowired
	private ICapAdvBackFundLogService capAdvBackFundLogService;

	@Autowired
    private ISysDictionaryApiService sysDictionaryApiService ;
		
	/**
	 * 到(垫款付款指令管理)列表页面
	 */
	@RequestMapping(value = "/toPayMentListPage.do", method = { RequestMethod.GET})
	public ModelAndView toPayMentListPage(HttpServletRequest request, HttpServletResponse response) {
		
		List<KeyValueVO> kvList = this.sysDictionaryApiService.getKvList(CapAdvFundConstant.CODE_FUND_STS_CD_CODE, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
		BaseLogUtils.info(logger, "toPayMentListPage", "跳转toPayMentListPage列表页面.",CurrentThreadContext.getCurrentUserName());
		ModelAndView mav = new ModelAndView("capital/capAdvFund/capAdvPayMentList");
		mav.addObject("kvList",kvList);
	    mav.addObject("kvListJson", JSONArray.fromObject(kvList));
		return mav;
	}
	
	/**
	 * 到(垫款及核销流水列表)列表页面
	 */
	@RequestMapping(value = "/toRecListPage.do", method = { RequestMethod.GET})
	public ModelAndView toRecListPage(HttpServletRequest request, HttpServletResponse response) {
		List<KeyValueVO> kvList = this.sysDictionaryApiService.getKvList(CapAdvFundConstant.CODE_FUND_STS_CD_CODE, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
		BaseLogUtils.info(logger, "toRecListPage", "跳转toRecListPage列表页面.",CurrentThreadContext.getCurrentUserName());
		ModelAndView mav = new ModelAndView("capital/capAdvFund/capAdvRecList");
		mav.addObject("kvList",kvList);
		return mav;
	}
	
	/**
	 * 到(核销付款指令列表)列表页面
	 */
	@RequestMapping(value = "/toCheckFkListPage.do", method = { RequestMethod.GET})
	public ModelAndView toCheckFkListPage(HttpServletRequest request, HttpServletResponse response) {
		List<KeyValueVO> kvList = this.sysDictionaryApiService.getKvList(CapAdvFundConstant.CODE_FUND_STS_CD_CODE, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
		BaseLogUtils.info(logger, "toCheckFkListPage", "跳转toCheckFkListPage列表页面.",CurrentThreadContext.getCurrentUserName());
		ModelAndView mav = new ModelAndView("capital/capAdvFund/capAdvCheckFkList");
		mav.addObject("kvList",kvList);
		return mav;
	}
	
	
	/**
	 * 加载(垫款付款指令管理)列表页面
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/payMentList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object payMentList(HttpServletRequest request, HttpServletResponse response) {
		BaseLogUtils.info(logger, "payMentList", "加载capAdvPayMentList列表页面.",CurrentThreadContext.getCurrentUserName());
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		
		String DKid = request.getParameter("dkid");
		String ruleNm = request.getParameter("ruleNm");
		String payAccNm = request.getParameter("payAccNm");//PAY_ACC_NM
		String dueAccNo = request.getParameter("dueAccNo");
		String assAmtStart = request.getParameter("assAmtStart");
		String assAmtEnd = request.getParameter("assAmtEnd");
		String isDel = request.getParameter("isDel");
		String batchId = request.getParameter("batchId");
		
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}
		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}
		CapAdvFundQueryCondition qc =new CapAdvFundQueryCondition();
		
		
		if (StringUtils.isNotEmpty(DKid)) {
			qc.setDkId(Long.parseLong(DKid));//垫款id
		}
		if (StringUtils.isNotEmpty(batchId)) {
			qc.setBatchId(Long.parseLong(batchId));//核销批次id
		}
		
		if (StringUtils.isNotEmpty(ruleNm)) {
			qc.setRuleNm(ruleNm);//垫款规则名称
		}
		if (StringUtils.isNotEmpty(payAccNm)) {
			qc.setPayAccNm(payAccNm);//付款账号
		}
		
		if (StringUtils.isNotEmpty(dueAccNo)) {
			qc.setDueAccNo(dueAccNo);//收款账户
		}
		if (StringUtils.isNotEmpty(assAmtStart)) {
			qc.setAssAmtStart(Long.parseLong(assAmtStart));//金额起
		}
		if (StringUtils.isNotEmpty(assAmtEnd)) {
			qc.setAssAmtEnd(Long.parseLong(assAmtEnd));//金额止
		}
		if (StringUtils.isNotEmpty(isDel)) {
			qc.setIsStart(isDel);// 成功失败
		}

		
		page.setCondition(qc);
		Pager searchAssetsListPage = this.capAdvBackFundLogService.searchPayMentListPage(page);
		
		List<CapAdvFundVO> list = (List<CapAdvFundVO>) searchAssetsListPage.getResultList();
		ListPageVO<CapAdvFundVO> listPage = new ListPageVO<CapAdvFundVO>(list, page.getTotalCount());
		BaseLogUtils.info(logger, "assetsList", "查询数据完成. DATA:" + JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
		return listPage;
	}
	
	
	/**
	 * 加载(垫款及核销流水)列表页面
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/payRecList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object payRecList(HttpServletRequest request, HttpServletResponse response) {
		BaseLogUtils.info(logger, "payMentList", "加载payRecList列表页面.",CurrentThreadContext.getCurrentUserName());
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		
		String paySchNo = request.getParameter("paySchNo");//支付表号
		String dkId = request.getParameter("dkid");//垫款付款指令ID
		String batchId = request.getParameter("batchId");//批次ID
		String fsTimeSart = request.getParameter("fsTimeSart");//发送时间起
		String fsTimeEnd = request.getParameter("fsTimeEnd");//发送时间止
		String sjtimeSart = request.getParameter("sjtimeSart");//实际付款时间起
		String sjtimeEnd = request.getParameter("sjtimeEnd");//实际付款时间止
		String isDel = request.getParameter("isDel");//付款状态
		
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}
		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}
		CapAdvFundQueryCondition qc =new CapAdvFundQueryCondition();
		
		if (StringUtils.isNotEmpty(paySchNo)) {
			qc.setPaySchNo(paySchNo);//支付表号
		}
		if (StringUtils.isNotEmpty(dkId)) {
			qc.setDkId(Long.parseLong(dkId));//垫款id
		}
		if (StringUtils.isNotEmpty(batchId)) {
			qc.setBatchId(Long.parseLong(batchId));//核销批次id
		}
		if (StringUtils.isNotEmpty(fsTimeSart)) {
			qc.setFsTimeSart(fsTimeSart);
		}
		if (StringUtils.isNotEmpty(fsTimeEnd)) {
			qc.setFsTimeEnd(fsTimeEnd);
		}
		if (StringUtils.isNotEmpty(sjtimeSart)) {
			qc.setSjtimeSart(sjtimeSart);
		}
		if (StringUtils.isNotEmpty(sjtimeEnd)) {
			qc.setSjtimeEnd(sjtimeEnd);
		}
		if (StringUtils.isNotEmpty(isDel)) {
			qc.setIsStart(isDel);//付款状态
		}

		
		page.setCondition(qc);
		Pager searchAssetsListPage = this.capAdvBackFundLogService.searchRecListPage(page);
		
		List<CapAdvFundVO> list = (List<CapAdvFundVO>) searchAssetsListPage.getResultList();
		ListPageVO<CapAdvFundVO> listPage = new ListPageVO<CapAdvFundVO>(list, page.getTotalCount());
		BaseLogUtils.info(logger, "assetsList", "查询数据完成. DATA:" + JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
		return listPage;
	}

	
	
//	
//	/**
//	 * 到列表页面
//	 */
//	@RequestMapping(value = "/toListPage.do", method = { RequestMethod.GET})
//	public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
//		BaseLogUtils.info(logger, "toListPage", "加载capAdvBackFundLogList列表页面.",CurrentThreadContext.getCurrentUserName());
//		ModelAndView mav = new ModelAndView("capital/capAdvFund/capAdvBackFundLogList");
//		return mav;
//	}
//	
//	/**
//	 * 到垫款资产列表页面
//	 */
//	@RequestMapping(value = "/toAssetsListPage.do", method = { RequestMethod.GET})
//	public ModelAndView toAssetsListPage(HttpServletRequest request, HttpServletResponse response) {
//		BaseLogUtils.info(logger, "toAssetsListPage", "加载toAssetsListPage列表页面.",CurrentThreadContext.getCurrentUserName());
//		ModelAndView mav = new ModelAndView("capital/capAdvFund/capAdvRuleInfoAssetsList");
//		return mav;
//	}
//	
//	/**
//	 * 详情页面
//	 */
//	@RequestMapping(value = "/toCapAvdBackLogModifyPage.do", method = { RequestMethod.GET})
//	public ModelAndView toSingleConfigModifyPage(HttpServletRequest request, HttpServletResponse response) {
//		BaseLogUtils.info(logger, "toSingleConfigModifyPage", "加载供应商配置维护页面.",CurrentThreadContext.getCurrentUserName());
//		ModelAndView view = new ModelAndView("capital/capAdvFund/DetailedListModify");
//		String paySchId = request.getParameter("paySchId");
//		view.addObject("paySchId",paySchId);
//		return view;
//	}
//	
//	/**
//	 * 详情页面
//	 */
//	@RequestMapping(value = "/toDetailedPage.do", method = { RequestMethod.GET})
//	public ModelAndView toDetailedPage(HttpServletRequest request, HttpServletResponse response) {
//		BaseLogUtils.info(logger, "toSingleConfigModifyPage", "加载供应商配置维护页面.",CurrentThreadContext.getCurrentUserName());
//		ModelAndView view = new ModelAndView("capital/capAdvFund/DetailedListModifyB");
//		String paySchId = request.getParameter("paySchId");
//		String paySchNo = request.getParameter("paySchNo");
//		view.addObject("paySchId",paySchId);
//		view.addObject("paySchNo", paySchNo);
//		return view;
//	}
//	
//	
//	/**
//	 * 资金还款记录
//	 */
//	@SuppressWarnings("unchecked")
//	@RequestMapping(value = "/fundBackLogInitList.do", method = { RequestMethod.GET})
//	@ResponseBody
//	public Object fundBackLogInitList(HttpServletRequest request, HttpServletResponse response) {
//		String currentPage = request.getParameter("page");
//		String pageSize = request.getParameter("pagesize");
//		
//		String paySchId = request.getParameter("paySchId");
//		
//		Pager page = new Pager();
//		if (StringUtils.isNotEmpty(currentPage)) {
//			page.setCurrentPage(Integer.parseInt(currentPage));
//		}
//
//		if (StringUtils.isNotEmpty(pageSize)) {
//			page.setEveryPage(Integer.parseInt(pageSize));
//		}
//		//查询支付表明细表 （计划还款日期）
//		PrjPrdPaySchDQueryCondition qcSchD = new PrjPrdPaySchDQueryCondition();
//		if (StringUtils.isNotEmpty(paySchId)) {
//			qcSchD.setPaySchId(Long.parseLong(paySchId));
//		}
//		List<PrjPrdPaySchDVO> searchList = this.prjPrdPaySchDService.searchList(qcSchD);
//		
//		//查询核销明细
//		CapFundVfDtlQueryCondition qcCapFundVfDtl = new CapFundVfDtlQueryCondition();
//		if (StringUtils.isNotEmpty(paySchId)) {
//			qcCapFundVfDtl.setPaySchId(Long.parseLong(paySchId));
//		}
//		page.setCondition(qcCapFundVfDtl);
//		Pager searchListPage = this.capFundVfDtlService.searchListPage(page);
//	        
//		
//		List<CapFundVfDtlVO> list = (List<CapFundVfDtlVO>) searchListPage.getResultList();
//		if(CollectionUtils.isNotEmpty(searchList)&&CollectionUtils.isNotEmpty(list)){
//        
//		for (int i = 0; i < list.size(); i++) {
//			//计划还款日期
//			if(searchList.get(i).getPaySchId().equals(list.get(i).getPaySchId())){
//				list.get(i).setPayDt(searchList.get(i).getPayDt());
//				
//				if(searchList.get(i).getArAmt()>0){
//					list.get(i).setVfStsCdNm("未结清");
//				}else{
//					list.get(i).setVfStsCdNm("已结清");
//				}
//			}
//			 //已结清 未结清  状态
//		  }
//		}
//		
//		
//		ListPageVO<CapFundVfDtlVO> listPage = new ListPageVO<CapFundVfDtlVO>(list, page.getTotalCount());
//		BaseLogUtils.info(logger, "fundBackLogInitList", "查询数据完成. DATA:" + JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
//		return listPage;
//	}
//
//	
//	
//	/**
//	 * 租赁项目资金回款记录
//	 */
//	@SuppressWarnings("unchecked")
//	@RequestMapping(value = "/fundpRrjBackLogitList.do", method = { RequestMethod.GET})
//	@ResponseBody
//	public Object fundpRrjBackLogitList(HttpServletRequest request, HttpServletResponse response) {
//		String currentPage = request.getParameter("page");
//		String pageSize = request.getParameter("pagesize");
//		String paySchId = request.getParameter("paySchId");
//		Pager page = new Pager();
//		if (StringUtils.isNotEmpty(currentPage)) {
//			page.setCurrentPage(Integer.parseInt(currentPage));
//		}
//		if (StringUtils.isNotEmpty(pageSize)) {
//			page.setEveryPage(Integer.parseInt(pageSize));
//		}
//		//项目产品支付表主信息表 (拿到客户id)
//		 PrjPrdPaySchMVO selectById = this.prjPrdPaySchMService.selectById(Long.parseLong(paySchId));
//		
//		//项目产品支付表主明细信息(计划还款日期)
//		PrjPrdPaySchDQueryCondition qcSchD = new PrjPrdPaySchDQueryCondition();
//		if (StringUtils.isNotEmpty(paySchId)) {
//			qcSchD.setPaySchId(Long.parseLong(paySchId));
//		}
//		List<PrjPrdPaySchDVO> PrjPrdPaySchDList = this.prjPrdPaySchDService.searchList(qcSchD);
//		
//		//逾期信息表
//        CapOverdueInfoQueryCondition CapOverdueInfoqc = new CapOverdueInfoQueryCondition();
//        if (StringUtils.isNotEmpty(selectById.getCstId())) {
//        	CapOverdueInfoqc.setCstId(selectById.getCstId());
//        }
//        if (StringUtils.isNotEmpty(paySchId)) {
//        	CapOverdueInfoqc.setPaySchId(Long.valueOf(paySchId));
//        }
//        CapOverdueInfoqc.setSortName("createDate");
//        CapOverdueInfoqc.setSortOrder("desc");
//
//        page.setCondition(CapOverdueInfoqc);
//        BaseLogUtils.info(logger, "fundpRrjBackLogitList", "查询客户逾期支付表汇总信息.DATA:" + JSONObject.toJSONString(CapOverdueInfoqc), CurrentThreadContext.getCurrentUserName());
//        Pager pager = this.capOverdueInfoService.searchOvdDtlListPage(page);
//	
//		List<CapOverdueInfoVO> list = (List<CapOverdueInfoVO>) pager.getResultList();
//		if(CollectionUtils.isNotEmpty(PrjPrdPaySchDList)&&CollectionUtils.isNotEmpty(list)){
//        
//		for (int i = 0; i < list.size(); i++) {
//			//计划还款日期
//			if(PrjPrdPaySchDList.get(i).getPaySchId().equals(list.get(i).getPaySchId())){
//				list.get(i).setPayDt(PrjPrdPaySchDList.get(i).getPayDt());
//				
//			}
//		  }
//		
//		
//		}
//		
//		
//		ListPageVO<CapOverdueInfoVO> listPage = new ListPageVO<CapOverdueInfoVO>(list, page.getTotalCount());
//		BaseLogUtils.info(logger, "fundBackLogInitList", "查询数据完成. DATA:" + JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
//		return listPage;
//	}
//	
//	
//	
//	
//	
//	/**
//	 * 垫款资产列表
//	 */
//	@SuppressWarnings("unchecked")
//	@RequestMapping(value = "/assetsList.do", method = { RequestMethod.GET})
//	@ResponseBody
//	public Object assetsList(HttpServletRequest request, HttpServletResponse response) {
//		String currentPage = request.getParameter("page");
//		String pageSize = request.getParameter("pagesize");
//		String paySchNO = request.getParameter("paySchNO");
//		String FKid = request.getParameter("FKid");
//		String DKid = request.getParameter("DKid");
//		String ruleNm = request.getParameter("ruleNm");
//		String assMthSart = request.getParameter("assMthSart");
//		String assMthEnd = request.getParameter("assMthEnd");
//		String assAmtStart = request.getParameter("assAmtStart");
//		String assAmtEnd = request.getParameter("assAmtEnd");
//		String isDel = request.getParameter("isDel");
//		Pager page = new Pager();
//		if (StringUtils.isNotEmpty(currentPage)) {
//			page.setCurrentPage(Integer.parseInt(currentPage));
//		}
//		if (StringUtils.isNotEmpty(pageSize)) {
//			page.setEveryPage(Integer.parseInt(pageSize));
//		}
//		CapAdvRvtDtlQueryCondition qc =new CapAdvRvtDtlQueryCondition();
//		if (StringUtils.isNotEmpty(paySchNO)) {
//			qc.setPaySchNo(paySchNO);
//		}
//		if (StringUtils.isNotEmpty(FKid)) {
//			qc.setFKid(Long.parseLong(FKid));	
//		 }
//		
//		if (StringUtils.isNotEmpty(DKid)) {
//			qc.setDKid(Long.parseLong(DKid));	
//		}
//		
//		if (StringUtils.isNotEmpty(ruleNm)) {
//			qc.setRuleNm(ruleNm);
//		}
//		if (StringUtils.isNotEmpty(assMthSart)) {
//			qc.setAssMthSart(assMthSart);
//		}
//		
//		if (StringUtils.isNotEmpty(assMthEnd)) {
//			qc.setAssMthEnd(assMthEnd);
//		}
//		if (StringUtils.isNotEmpty(assAmtStart)) {
//			qc.setAssAmtStart(Long.parseLong(assAmtStart));
//		}
//		if (StringUtils.isNotEmpty(assAmtEnd)) {
//			qc.setAssAmtEnd(Long.parseLong(assAmtEnd));
//		}
//		if (StringUtils.isNotEmpty(isDel)) {
//			qc.setIsStart(Integer.parseInt(isDel));
//		}
//		
//		page.setCondition(qc);
//		Pager searchAssetsListPage = this.capAdvBackFundLogService.searchAssetsListPage(page);
//		
//		List<CapOverdueInfoVO> list = (List<CapOverdueInfoVO>) searchAssetsListPage.getResultList();
//		ListPageVO<CapOverdueInfoVO> listPage = new ListPageVO<CapOverdueInfoVO>(list, page.getTotalCount());
//		BaseLogUtils.info(logger, "assetsList", "查询数据完成. DATA:" + JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
//		return listPage;
//	}
	
	
	

}

